home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Gigarom 1
/
Gigarom Macintosh Archives (Quantum Leap)(CDRM1080320)(1993).iso
/
FILES
/
DEV
/
I-Z
/
XLisp_1.6.cpt
/
MacFun2.MEM
< prev
next >
Wrap
Text File
|
1985-12-04
|
5KB
|
126 lines
Macintosh Toolbox Interface Functions
November 3, 1985
Here are some functions that have been added to XLISP in the version 1.5b
release. They are specific to the Macintosh version and are intended to
provide a low level interface to the Macintosh toolbox. They are VERY
dangerous!! Any incorrect use of these function could easily result in
a system crash and/or disk file corruption. Use these functions carefully
and make sure you backup your files before trying anything.
(toolbox <trap> [<arg>]...) Call a toolbox procedure (no return value)
(toolbox-16 <trap> [<arg>]...) Call a toolbox function with a 16 bit value
(toolbox-32 <trap> [<arg>]...) Call a toolbox function with a 32 bit value
All of these functions make it possible to call the stack-based toolbox
routines. All of the arguments are integers (FIXNUMs) and they are all
interpreted as 16 bit values. If you need to pass a 32 bit address, you'll
have to take it apart and pass it as two separate 16 bit arguments. Pass
only as many arguments as the toolbox routine expects. Additional arguments
won't be ignored. They will cause a system bomb!
The first argument of each of these functions is the 16 bit trap word used
by assembly language programmers to call the toolbox routine. You can
specify it in hex if you use the reader facility for entering hex numbers:
#xA954 will read as the decimal number 43348
#x100 will read as the decimal number 256
The remaining arguments are pushed onto the stack before the trap word
is executed. They are all treated as 16 bit integers.
The value returned will be the value left on the stack by the toolbox
routine. Any toolbox routines that return values in reference parameters
will need to be handled by passing the address of a place to store the
result. You can do this by some fancy manipulation of the ADDRESS-OF
function. Be careful.
(NewHandle <size>) Allocate a relocatable block of memory
(NewPtr <size>) Allocate a non-relocatable block of memory
These functions allocate memory. The first returns a handle to the space
allocated and the second returns a pointer to the space. In both cases,
the size is an integer. The result is also an integer whose value is the
32 bit address of the handle or allocated space.
(HiWord <num>) Return the high order 16 bits of an integer
(LoWord <num>) Return the low order 16 bits of an integer
These functions simplify separating a 32 bit value into two 16 bit halves.
They are useful where it is necessary to pass 32 bit pointers or handles
to the toolbox interface functions.
*command-window* Address of the command window (FIXNUM)
*graphics-window* Address of the graphics window (FIXNUM)
These global variables contain the WindowPtrs to the command and graphics
windows in the standard XLISP user interface.
These functions will eventually become part of the generic version of
XLISP.
(peek <adr>) Peek at a value in memory
(poke <adr> <val>) Poke a value into memory
In both cases, the address is an integer (FIXNUM). The number of bits
that are significant in the address depends on the host processor. For
the 68000 (the processor in the Macintosh), FIXNUMs are 32 bits and so
are addresses, so all bits are significant. The value returned by
PEEK and accepted by POKE is also an integer. The number of significant
bits is determined by the size of an 'int' in the underlying C
implementation. For the Macintosh, 16 bits are significant.
(address-of <expr>) Get the machine address of an XLISP node
This function returns the location in memory of the specified XLISP value.
It returns an integer (FIXNUM) whose value is the address of the node used
internally to represent the value.
(read-char-no-hang) Read a character from the keyboard without waiting
This function checks if a character is available from the keyboard. If
a character is available, READ-CHAR-NO-HANG returns the character without
echoing it. The character is returned as a integer whose value is the
ASCII code of the character. If no character is available, the function
returns NIL.
If you need to call any of the register based toolbox routines, you will
have to resort to something like the following example. Here we are
building an array containing machine code and then fooling XLISP into
thinking that it is a built-in function. This is also VERY dangerous!
Use with caution!
; (make-subr <code-list>) Make a SUBR node
(defun make-subr (code &aux subr hunk adrs)
; allocate some space for the code
(setq hunk (NewPtr (* (length code) 2)))
; stuff the code into the space
(dotimes (i (length code))
(poke (+ hunk i i) (car code))
(setq code (cdr code)))
; create a node we can convert to a SUBR
(setq subr (+ 1 1))
(setq adrs (address-of subr))
; initialize the node type (SUBR = 1)
(poke adrs #x100)
; store the address of the code space
(poke (+ adrs 2) (HiWord hunk))
(poke (+ adrs 4) (LoWord hunk))
; return the new SUBR node
subr)
; try it out with the SysBeep(10) test
(setq beep (make-subr '(
#x3F3C #x000A ; move.w #10,-(SP)
#xA9C8 ; _SysBeep
#x4280 ; clr.l D0 ; return NIL to XLISP
#x4E75))) ; rts